package com.example.demo.util;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname TestTryCatch
 * @Description TODO
 * @Date 2019/12/5 12:24
 * @Created by yby
 */
public class TestTryCatch {
    public int a = 0;

    public int method(){
        int b = 0;
        try{
          throw new Exception();
        }catch (Exception e){
            a = 1;
            b = 1;
            return b ;
        }finally {
            a = 2;
            b =2;
        }
        //a = 3;
    }
    public static String test() {
        try {
            throw new Exception();
        } catch (Exception e) {
            return "catch";
        } finally {
            return "finally";
        }
    }

    public static int query() {
        int i = 0;
        try {
            System.out.print("try\n");
            return i += 10;
        } catch (Exception e) {
            System.out.print("catch\n");
            i += 20;
        } finally {
            System.out.print("finally-i:"+i + "\n");
            i += 10;
            System.out.print("finally\n");
            return i;
        }
    }

    public static List getList(){
        List list = new ArrayList<>();
        try{
            list.add("tom");
            throw new Exception();
        }catch (Exception e){
            list.add("bob");
            return list;
        }finally {
            list.add("hhb");
        }
    }
        public static void main(String[] args) {
        TestTryCatch TestTryCatch =new TestTryCatch();
        TestTryCatch.method();
        System.out.println(TestTryCatch.method());
        System.out.println(TestTryCatch.a);
            System.out.println(test());
            System.out.println(TestTryCatch.test());

           int j = query();        System.out.println(j);

            System.out.println(getList());
    }
}
